<template>
  <div id="topSearch">
    <div class="search-box">
      <el-form
        :inline="true"
        :model="searchInfo"
        ref="ruleForm"
        class="demo-form-inline"
      >
        <el-form-item label="A学员:" prop="dpAccount">
          <el-input
            size="small"
            v-model="searchInfo.dpAccount"
            placeholder="请输入A学员大鹏号"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item label="A学员状态:" prop="studyStatus">
          <el-select
            size="small"
            v-model="searchInfo.studyStatus"
            placeholder="请选择学员状态"
            clearable
          >
            <el-option
              v-for="(item, index) in studentState"
              :key="index"
              :label="item.dictLabel"
              :value="item.dictValue"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="发放状态:" prop="grantStatus">
          <el-select
            size="small"
            v-model="searchInfo.grantStatus"
            placeholder="请选择发放状态"
            clearable
          >
            <el-option
              v-for="(item, index) in grantState"
              :key="index"
              :label="item.dictLabel"
              :value="item.dictValue"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="被推荐人报名时间:" prop="createTime">
          <el-date-picker
            size="small"
            v-model="searchInfo.createTime"
            type="daterange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            value-format="yyyy-MM-dd HH:mm:ss"
            @change="checkedCreateTime"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="奖励到账时间:" prop="accountTime">
          <el-date-picker
            size="small"
            v-model="searchInfo.accountTime"
            type="daterange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            value-format="yyyy-MM-dd HH:mm:ss"
            @change="checkedAccountTime"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item class="s-btn">
          <el-button type="success" icon="el-icon-search" @click="toSearch">
            查询
          </el-button>
          <el-button type="success" plain @click="resetForm('ruleForm')">
            重置
          </el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>
<script>
import { sysNormalDisable } from '@utils/dictionariesFunc'
export default {
  data() {
    return {
      studentState: [],
      grantState: [],
      searchInfo: {
        dpAccount: '',
        studyStatus: '',
        grantStatus: '',
        regStartTime: '',
        regEndTime: '',
        rewardStartTime: '',
        rewardEndTime: '',
        createTime: '',
        accountTime: ''
      }
    }
  },
  mounted() {
    this.getStatusList()
  },
  methods: {
    async getStatusList() {
      this.studentState = await sysNormalDisable('partner_award_study_status') //学员状态
      this.grantState = await sysNormalDisable('partner_award_grant_status') //发放状态
    },
    checkedCreateTime(val) {
      this.searchInfo.regStartTime = val && val.length > 1 ? val[0] : ''
      this.searchInfo.regEndTime = val && val.length > 1 ? val[1] : ''
    },
    checkedAccountTime(val) {
      this.searchInfo.rewardStartTime = val && val.length > 1 ? val[0] : ''
      this.searchInfo.rewardEndTime = val && val.length > 1 ? val[1] : ''
    },
    toSearch() {
      const obj = Object.assign({}, this.searchInfo)
      delete obj.createTime
      delete obj.accountTime
      this.$emit('toSearch', obj)
    },
    resetForm(formName) {
      this.$refs[formName].resetFields()
      this.checkedCreateTime()
      this.checkedAccountTime()
    }
  }
}
</script>
<style lang="less" scoped></style>
